package com.fyzk.bean;

import com.fyzk.utils.LotteryIDUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 17/4/25.
 */

public class MissValueBean implements LotteryIDUtils{


    /**
     * errorcode : 0
     * msg : 成功
     * data : [{"lotteryType":2007,"phase":"17042522","key":"2007MV_RX","mvData":"{\"miss\":[3,1,3,3,1,0,0,1,0,0,0]}"},{"lotteryType":2007,"phase":"17042522","key":"2007MV_Q1","mvData":"{\"ge\":[12,14,13,3,16,1,15,2,0,17,9]}"},{"lotteryType":2007,"phase":"17042522","key":"2007MV_Q2","mvData":"{\"ge\":[3,1,7,16,25,0,8,9,5,6,2],\"shi\":[12,14,13,3,16,1,15,2,0,17,9]}"},{"lotteryType":2007,"phase":"17042522","key":"2007MV_Q3","mvData":"{\"bai\":[12,14,13,3,16,1,15,2,0,17,9],\"ge\":[13,19,4,39,18,6,3,1,7,2,0],\"shi\":[3,1,7,16,25,0,8,9,5,6,2]}"},{"lotteryType":2007,"phase":"17042522","key":"2007MV_Q2Z","mvData":"{\"miss\":[3,1,7,3,16,0,8,2,0,6,2]}"},{"lotteryType":2007,"phase":"17042522","key":"2007MV_Q3Z","mvData":"{\"miss\":[3,1,4,3,16,0,3,1,0,2,0]}"}]
     */

    private String errorcode;
    private String msg;
    /**
     * lotteryType : 2007
     * phase : 17042522
     * key : 2007MV_RX
     * mvData : {"miss":[3,1,3,3,1,0,0,1,0,0,0]}
     */

    private List<DataBean> data;

    public String getErrorcode() {
        return errorcode;
    }

    public void setErrorcode(String errorcode) {
        this.errorcode = errorcode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {
        private int lotteryType;
        private String phase;
        private String key;
        private String mvData;

        public int getLotteryType() {
            return lotteryType;
        }

        public void setLotteryType(int lotteryType) {
            this.lotteryType = lotteryType;
        }

        public String getPhase() {
            return phase;
        }

        public void setPhase(String phase) {
            this.phase = phase;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getMvData() {
            return mvData;
        }

        public void setMvData(String mvData) {
            this.mvData = mvData;
        }
    }

    public List<List<Integer>> missValue(String key) {
        List<List<Integer>> missNums = new ArrayList<>();
        String value = getValue(key); // "{\"miss\":[3,1,3,3,1,0,0,1,0,0,0]}"
        String[] labels = null;

        // 11选5
        if (key.equals("2007MV_RX") || key.equals("2007MV_Q2Z") || key.equals("2007MV_Q3Z") ||
                key.equals("2005MV_RX") || key.equals("2005MV_Q2Z") || key.equals("2005MV_Q3Z") ||
                key.equals("2008MV_RX") || key.equals("2008MV_Q2Z") || key.equals("2008MV_Q3Z")) {
            labels = new String[]{"miss"};
        }
        if (key.equals("2007MV_Q1") || key.equals("2005MV_Q1") || key.equals("2008MV_Q1")) {
            labels = new String[]{"ge"};
        }
        if (key.equals("2007MV_Q2") || key.equals("2005MV_Q2") || key.equals("2008MV_Q2")) {
            labels = new String[]{"shi","ge"};
        }
        if (key.equals("2007MV_Q3") || key.equals("2005MV_Q3") || key.equals("2008MV_Q3") ) {
            labels = new String[]{"bai","shi","ge"};
        }

        // 双色球
        if (key.equals("1001MV_X")) {
            labels = new String[]{"red","blue"};
        }

        // 大乐透
        if (key.equals("2001MV_X")) {
            labels = new String[]{"qian","hou"};
        }

        // 福彩3D、排列3
        if (key.equals("1002MV_ZX") || key.equals("2002MV_ZX")) {
            labels = new String[]{"bai","shi","ge"};
        }
        if (key.equals("1002MV_Z36") || key.equals("1002MV_Z36HZ") || key.equals("1002MV_ZXHZ") ||
                key.equals("2002MV_Z36") || key.equals("2002MV_Z36HZ") || key.equals("2002MV_ZXHZ")) {
            labels = new String[]{"miss"};
        }
        if (key.equals("1002MV_Z3") || key.equals("2002MV_Z3")) {
            labels = new String[]{"dan", "shuang"};
        }

        // 排列5
        if (key.equals("2003MV_ZX")) {
            labels = new String[]{"wan","qian","bai","shi","ge"};
        }

        // 七星彩
        if (key.equals("2004MV_ZX")) {
            labels = new String[]{"baiwan","shiwan","wan","qian","bai","shi","ge"};
        }

        // 七乐彩
        if (key.equals("1003MV_X")) {
            labels = new String[]{"miss"};
        }

        // 快三
        if (key.equals("1008MV_60") || key.equals("1008MV_30") || key.equals("1008MV_11") ||
                key.equals("1008MV_00")) {
            labels = new String[]{"miss"};
        }
        if (key.equals("1008MV_10")) {
            labels = new String[]{"dan","shuang"};
        }

        if (key.equals("1009MV_60") || key.equals("1009MV_30") || key.equals("1009MV_11") ||
                key.equals("1009MV_00")) {
            labels = new String[]{"miss"};
        }
        if (key.equals("1009MV_10")) {
            labels = new String[]{"dan","shuang"};
        }

        if (key.equals("1010MV_60") || key.equals("1010MV_30") || key.equals("1010MV_11") ||
                key.equals("1010MV_00")) {
            labels = new String[]{"miss"};
        }
        if (key.equals("1010MV_10")) {
            labels = new String[]{"dan","shuang"};
        }

        // 快乐扑克
        if (key.equals("2009MV_RX") || key.equals("2009MV_BX") || key.equals("2009MV_BZ") ||
                key.equals("2009MV_DZ") || key.equals("2009MV_HS") || key.equals("2009MV_SZ") ||
                key.equals("2009MV_TH")) {
            labels = new String[]{"miss"};
        }

        // 快乐十分
        if (key.equals("1012MV_H1") || key.equals("1012MV_S1") || key.equals("1012MV_RX") ||
                key.equals("1013MV_H1") || key.equals("1013MV_S1") || key.equals("1013MV_RX")) {
            labels = new String[]{"miss"};
        }
        if (key.equals("1012MV_Q3") || key.equals("1013MV_Q3")) {
            labels = new String[]{"bai","shi","ge"};
        }

        // 时时彩
        if (key.equals("1007MV_5X")) {
            labels = new String[]{"wan","qian","bai","shi","ge"};
        }
        if (key.equals("1007MV_DD")) {
            labels = new String[]{"shiDX","geDX"};
        }
        if (key.equals("1007MV_2ZX") || key.equals("1007MV_2ZXHZ") || key.equals("1007MV_Z36")) {
            labels = new String[]{"miss"};
        }

        if (labels != null) {
            missNums = getMiss(value, labels);
        }
        return missNums;
    }

    private String getValue(String key) {
        String missInfo = "";
        for (DataBean info : data) {
            if (info.getKey().equals(key)) {
                missInfo = info.getMvData();
                break;
            }
        }
        return missInfo;
    }

    private List<List<Integer>> getMiss(String value, String[] labels) {
        List<List<Integer>> missArray = new ArrayList<>();
        try {
            JSONObject obj = new JSONObject(value);
            for (int i = 0; i < labels.length; i++) {
                if (obj.has(labels[i])) {
                    List<Integer> mArray = new ArrayList<>();
                    JSONArray array = obj.getJSONArray(labels[i]);
                    for (int j = 0; j < array.length(); j++) {
                        mArray.add(array.getInt(j));
                    }
                    missArray.add(mArray);
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return missArray;
    }

}
